/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.service;

import java.util.ArrayList;
import java.util.List;

import javacommon.base.BaseManager;
import javacommon.base.EntityDao;
import javacommon.util.org.TreeData;
import javacommon.util.org.TreeUtils;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.page.Page;

import com.tech15.core.dao.DeptDao;
import com.tech15.core.dao.SysUserDao;
import com.tech15.core.model.Dept;
import com.tech15.core.vo.query.DeptQuery;

/**
 * @author badqiu email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */

@Service
@Transactional
public class DeptManager extends BaseManager<Dept,Long>{

	private DeptDao deptDao;
	private SysUserDao sysUserDao;
	
	public void setDeptDao(DeptDao dao) {
		this.deptDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.deptDao;
	}
	public List<Dept> findLevelDept(){
		return deptDao.findLevelDept();
	}
	/**
	 * json格式部门树
	 * @return
	 */
	@Transactional(readOnly=true)
	public List<TreeData> findDeptTree(){
		List<TreeData> tdDataList = new ArrayList<TreeData>();
		List<Dept> depts = deptDao.findAllParentByDid();
		for(Dept d : depts){
			Dept dept = deptDao.loadTree(d.getDeptid());
			TreeData td = TreeUtils.setDeptContent(dept);
			tdDataList.add(td);
		}
		return tdDataList;
	}
	
	@Transactional(readOnly=true)
	public List<Dept> quickSelectDept(){
		return deptDao.quickSelectDept();
	}
	
	@Transactional(readOnly=true)
	public List<Dept> selectDept(){
		return deptDao.selectDept();
	}
	
	@Transactional(readOnly=true)
	public List<Dept> selectDeptByDeptid(Long deptid,String deptname){
		return deptDao.selectDeptByDeptid(deptid,deptname);
	}
	
	@Transactional(readOnly=true)
	public Page findPage(DeptQuery query) {
		return deptDao.findPage(query);
	}
	
}
